package com.gxa.saas.controller;

import com.gxa.saas.pojo.ClientType;
import com.gxa.saas.service.ClientTypeService;
import com.gxa.saas.utils.JsonResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
@Controller
@ResponseBody
@RequestMapping("/clientType")
public class ClientTypeMapperController {
    @Autowired
    ClientTypeService clientTypeService;

    @ApiOperation("添加用户信息的方法")
    @RequestMapping(value = "/TypeInsert",method ={RequestMethod.POST})
    public Map insert(ClientType clientType){
        Integer inert = clientTypeService.inert(clientType);
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd 'at' HH:mm:ss z");
        Date date = new Date(System.currentTimeMillis());
        System.out.println(formatter.format(date));
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("添加成功");
        jsonResult.setData(inert);
        return jsonResult.getMap();
    }
    @ApiOperation("修改用户信息的方法")
    @RequestMapping(value = "/TypeUpdate",method ={RequestMethod.POST})
    public Map update(ClientType clientType){
        clientTypeService.update(clientType);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("修改成功");
        return jsonResult.getMap();
    }
    @ApiOperation("删除用户信息的方法")
    @RequestMapping(value = "/TypeDelete",method ={RequestMethod.POST})
    public Map delete(Integer id){
        clientTypeService.delete(id);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("删除成功");
        return jsonResult.getMap();
    }
    @ApiOperation("全部查询用户信息的方法")
    @RequestMapping(value = "/TypeSelectAll", method = {RequestMethod.POST})
    public Map selectAll() {
        List<ClientType> clientTypes = clientTypeService.selectAll();
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.setData(clientTypes);
        return jsonResult.getMap();
    }
    @ApiOperation("分页查询用户信息的方法")
    @RequestMapping(value = "/TypeSelectByPage", method = {RequestMethod.POST})
    public Map selectByPage(@RequestParam(value = "page") Integer page,
                            @RequestParam(value = "limit") Integer limit) {
        List<ClientType> clientTypes = clientTypeService.selectAll();
        List<ClientType> clients = clientTypeService.selectByPage(page, limit);
        System.out.println(page);
        System.out.println(limit);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("200");
        jsonResult.setMsg("查询成功");
        jsonResult.set("totalCount",clientTypes.size());
        jsonResult.setData(clients);
        return jsonResult.getMap();
    }
}
